<?php
	$templates = getContentTemplates();
	$groups = getGroups();
	$modules = getModulesList();
	$htmls = getHTMLList();
	$videos = getVideos('all', 0);
	$galleries = getPhotoGals('all', 0);
	
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	
	switch ($_POST['action'])
	{
		case 'new_template':
			if(($_POST['title'] != '') && ($_REQUEST['site'] > 0))
			{ addContentTemplate($_POST['title'], $_REQUEST['site']); }
			$i=0;
			if($_POST['temp_id'])
			{
				foreach($_POST['temp_id'] as $id)
				{
					updateContentTemplate($id, $_POST['temp_title'][$i], $_POST['access'][$i], $_POST['site_area'][$i]);
					$i++;
				}
			}
			if($_POST['activate'] > 0)
			{  setContentActive($_POST['activate'], 1); }
			if($_POST['deactivate'] > 0)
			{  setContentActive($_POST['deactivate'], 0); }
			if($_POST['delete_template'] > 0)
			{ deleteContent($_POST['delete_template']); }
			$templates = getContentTemplates();
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				if($_POST['list_item_id'])
				{
					$i=0;
					foreach($_POST['list_item_id'] as $id)
					{
						updateListItem($id, $_POST['content_type'][$i], $_POST['content_id'][$i], $_POST['list_item_access'][$i]);
						$i++;
					}
				}
				if($_POST['list_item_activate'] > 0)
				{  setListItemActive($_POST['list_item_activate'], 1); }
				if($_POST['list_item_deactivate'] > 0)
				{  setListItemActive($_POST['list_item_deactivate'], 0); }
				if($_POST['list_item_delete'] > 0)
				{ deleteContentListItems($_POST['list_item_delete'], 0); }
				if($_POST['list_item_up'] > 0)
				{  moveListItemUp($_POST['list_item_up']); }
				if($_POST['list_item_down'] > 0)
				{  moveListItemDown($_POST['list_item_down']); }
				
				if($_POST['add_new_list'] != '')
				{ addTemplateList($item['id']); }
				if($_POST['list_id'])
				{
					$i=0;
					foreach($_POST['list_id'] as $id)
					{
						updateList($id, $_POST['direction'][$i], $_POST['access'][$i]);
						$i++;
					}
				}
				if($_POST['list_activate'] > 0)
				{  setListActive($_POST['list_activate'], 1); }
				if($_POST['list_deactivate'] > 0)
				{  setListActive($_POST['list_deactivate'], 0); }
				if($_POST['list_delete'] > 0)
				{ deleteContentList($_POST['list_delete'], 0); }
				if($_POST['list_up'] > 0)
				{  moveListUp($_POST['list_up']); }
				if($_POST['list_down'] > 0)
				{  moveListDown($_POST['list_down']); }
				if($_POST['new_list_item'] > 0)
				{  addListItem($_POST['new_list_item']);}
			}
			break;
	}
	if($item['id'] > 0)
	{ $item = getContentTemplate($item['id']); }
?>